/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Kemasan;

/**
 *
 * @author Dell
 */
public class KemasanTableModel extends AbstractTableModel {

    private List<Kemasan> kemas = new ArrayList<Kemasan>();

    public KemasanTableModel(List<Kemasan> kemas) {
        this.kemas = kemas;
    }

    public void deleteKemasan(int row) {
        kemas.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updateKemasan(int row, Kemasan kemasan) {
        kemas.set(row, kemasan);
        fireTableRowsUpdated(row, row);
    }

    public void addKemasan(Kemasan kemasan) {
        kemas.add(kemasan);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    @Override
    public int getRowCount() {
        return kemas.size();
    }

    @Override
    public int getColumnCount() {
        return 2;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Kemasan b = kemas.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return b.getIdKemasan();
            case 1:
                return b.getNamaKemasan();
            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID KEMASAN";
            case 1:
                return "NAMA KEMASAN";
            default:
                return "";
        }
    }
}
